var that,timer,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  qrcode = require('../../utils/qrcode.js'),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow:!1,
    isshow1:!1,
    orderId:0,
    newcouponArr:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    console.log(JSON.parse(options.data),'optin');
    that.setData({data:JSON.parse(options.data),orderId:options.orderId},()=>{
      that.getdata();
    })
  },
  getdata(){
    let {data,orderId}=that.data,total=0,qualificationsList=[],newcouponArr=[]
    api.chargegrantshare(orderId,res=>{
      if(res.data.code==0){
        console.log(res.data,'chargegrantshare');
        let {couponArr,num,shareKey} = res.data.entity.data
        if(num>0){
          that.setData({isshow:!0})
          couponArr.forEach(x=>{
            // total+=Number(x.fee)
            qualificationsList.push(x)
          })
          that.setData({qualificationsList,shareKey})
        }
      }
    })
    api.chargegrantcoupon(orderId,res=>{
      if(res.data.code==0){
        console.log(res.data,'chargegrantcouponchargegrantcoupon');
        let {couponArr,num} = res.data.entity.data
        if(num>0){
          couponArr.forEach(x=>{
            total+=Number(x.fee)
            newcouponArr.push(x)
          })
          that.setData({newcouponArr,total})
        }
      }
    })
    data.chargeFeearr=Number(data.chargeFee).toFixed(2).split('.')
    data.payFeearr=Number(data.payFee).toFixed(2).split('.')
    data.savearr=Number(data.save).toFixed(2).split('.')
    that.setData({data})
    let userinfo=wx.getStorageSync('userInfo')
    that.setData({userinfo})
  },
  close(){
    console.log(11111);
    that.setData({isshow:!1,isshow1:!1})
  },
  lookgift(){
    that.setData({isshow1:!0})
  },
  toindex(){
    wx.switchTab({
      url: '../index/index',
    })
  },
  torechargeRecord(){
    wx.redirectTo({
      url: '../rechargeRecord/rechargeRecord',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    that.setData({isshow:!1,isshow1:!1})
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let {shareKey,userinfo} = that.data
    if(res.from === 'button'){
      console.log('触发页面内的分享按钮',res.target);
      let shareObj = {
        imageUrl:'../pic/shareimg.png',
        title: '您身边的加油好帮手',
        path: 'pages/index/index?shareKey='+shareKey+'&userinfo='+JSON.stringify(userinfo)
      }
      return shareObj
    }
  }
})